package Servlet;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.util.Enumeration;

public class HelloServlet extends HttpServlet {
	@Override
	protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
		System.out.println("------------Get请求-------------------");
		String usernamename=req.getParameter("username");
		String age=req.getParameter("age");
		System.out.println("username="+usernamename);
		System.out.println("age="+age);

		//从Request对象中获取请求信息
		//请求行
		String method =req.getMethod();
		System.out.println("请求方式："+method);
		//获取的是部分路径
		System.out.println("请求的URI:"+req.getRequestURI());
		//获取的是绝对路径
		System.out.println("请求的URL:"+req.getRequestURL());
		System.out.println("协议："+req.getProtocol());

		//请求头
		Enumeration<String > headerNames=req.getHeaderNames();
		while(headerNames.hasMoreElements()) {
			String name=headerNames.nextElement();
			String value=req.getHeader(name);
			System.out.println("name:"+value);
		}

		//获取地址栏？后面的参数内容，中文是乱码的 地址栏的信息编码都是ISO-8859-1
		String queryString =req.getQueryString();
		System.out.println(queryString);
	}

	@Override
	protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
		System.out.println("------------Post请求-------------------");
	}
}
